package test.hash;

public class Solution2 {

    public int lengthOfLongestSubstringTwoDistinct(String s) {
        //在此处写入代码

        int left = 0;
        int right = 0;
        int count = 0;
        int[] map = new int[128];

        while (right < s.length()) {

            if (map[s.charAt(right++)]++ == 0) {
                count++;
            }
            if (count > 2) {
                if (--map[s.charAt(left++)] == 0) {
                    count--;
                }
            }
        }

        return right - left;
    }
}
